USE [davit_gdait_db2]
GO

EXEC sys.sp_dropextendedproperty @name=N'MS_Description' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'INDICATOR_VALUE_TYPE', @level2type=N'CONSTRAINT',@level2name=N'CK_INDICATOR_VALUE_TYPE_DATE'

GO

ALTER TABLE [dbo].[INDICATOR_VALUE_TYPE] DROP CONSTRAINT [CK_INDICATOR_VALUE_TYPE_DATE]
GO

ALTER TABLE [dbo].[INDICATOR_VALUE_TYPE]  WITH NOCHECK ADD  CONSTRAINT [CK_INDICATOR_VALUE_TYPE_DATE] CHECK  
(
	(day([DATE]) = 1) and
(
	([VALUE_TYPE] = 'm') or
	([VALUE_TYPE] = 'q' AND month([DATE]) in (1,4,7,10)) or
	([VALUE_TYPE] = 'r') and month([DATE]) = 1
	)
)
GO

ALTER TABLE [dbo].[INDICATOR_VALUE_TYPE] CHECK CONSTRAINT [CK_INDICATOR_VALUE_TYPE_DATE]
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Check if provided Date is a start of quarter' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'INDICATOR_VALUE_TYPE', @level2type=N'CONSTRAINT',@level2name=N'CK_INDICATOR_VALUE_TYPE_DATE'
GO


